﻿using System;
using System.Collections.Generic;
using Moq;
using Ninject.Modules;
using Spotted.Web.Data;
using Spotted.Web.Data.DataProvider;
using Spotted.Web.Data.Entities;
using Spotted.Web.Data.Result;

namespace Spotted.WebApi.Tests
{
    internal class MoqNinjectModule : NinjectModule
    {
        internal MoqNinjectModule()
        {
            UserRepository = new List<User>();
        }

        #region Overrides of NinjectModule

        /// <summary>
        /// Loads the module into the kernel.
        /// </summary>
        public override void Load()
        {
            // bind our user data provider
            var mockProvider = new Mock<IUserDataProvider>();

            // general valid case
            mockProvider.Setup(m => m.CreateUser(It.Is<User>(u => u != null)))
                .Returns(new CreateUserResult { ResultCode = ResultCode.Success, UserToken = Guid.NewGuid().ToString() });

            // duplicate case
            mockProvider.Setup(m => m.CreateUser(It.Is<User>(u => u.EmailAddress.Contains("duplicate@example.com"))))
                .Returns(new CreateUserResult {ResultCode = ResultCode.DuplicateEmail});

            // perform binding on the mocked userprovider type
            Bind<IUserDataProvider>().ToConstant(mockProvider.Object);
        }

        #endregion

        private IList<User> UserRepository { get; set; }
    }
}
